package com.api.shopapi.controller;

import com.alibaba.fastjson.JSONObject;

import com.api.shopapi.entity.MyResult;
import com.api.shopapi.entity.PreCheck;
import com.api.shopapi.entity.SysNation;
import com.api.shopapi.service.SysNationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("SysNation")
public class SysNationController extends BaseController {

    @Autowired
    @Qualifier("SysNationServiceImplOne")
    private SysNationService sysNationService;


    //查询所有民族
    @RequestMapping(value = "List",method = RequestMethod.POST)
    public MyResult List(@RequestBody JSONObject jsonObject){
        try {
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");
            String staffCode = jsonObject.getString("staffCode");
            PreCheck preCheck = checkSignAdmInterface(timeStr, sign,staffCode,"/SysNation/List");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }
            List<SysNation> sysNations =sysNationService.getList();
            return success(sysNations);
        } catch (Exception e) {
            insertError("/SysNation/List",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }

    //App查询所有民族
    @RequestMapping(value = "ListApp",method = RequestMethod.POST)
    public MyResult ListAPP(@RequestBody JSONObject jsonObject){
        try {
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");

//            if (!checkSignPC(timeStr, sign)) {
//                return failed("签名错误");
//            }
            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/SysNation/ListApp");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }

            List<SysNation> sysNations =sysNationService.getList();
            return success(sysNations);
        } catch (Exception e) {
            insertError("/SysNation/ListApp",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }



}
